var windowName = "userCash";
var Page,logs;
apiready = function(){

    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    logs = new List();
    Page = createVM("#Page",{
        //页面数据
        curTab:0
        ,money:""
        ,card:""
        ,cards:[]
        ,en: {
            name:"",
            card:"",
            bank:"",
            bankAddress:""
        }
        ,log:[]
    },{
        //页面方法
        "init":function () {
            var card = getLocData("card");
            this.card = card
            getCard(this)
            logs.setUrl("/app/user/money/cash/log").setCbFunc(function (res) {
                clearLoading();
                Page.log = res;
            }).getList()

            getMyCards(Page)
        }
        ,setCur: function (index) {
            this.cur = index
        }
        ,addCard:function () {
            apiPost("/api/moneyUserCards", this.en, function (res,code) {
                logJson(res,"/api/moneyUserCards")
                showToast("OK")
                if (code == 200) {
                    getCard(Page)
                }
            });
        }
        ,doCash:function () {
            apiPost("/app/user/money/cash", {money:this.money}, function (res,code) {
                logJson(res,"/app/user/money/cash");
                showToast(res.message)
                if (code == 200) {
                    // getCard(Page)
                    logs.reload()
                    Page.curTab = 1
                }
            });
        }
        ,useThis:function (card) {
            this.en = card
            this.en.id = ''
            this.addCard()
        }

    })
    Page.init();
    onPullUpLoadMore(function () {
        if (Page.curTab == 1) {
            logs.getList();
        }else {
            clearLoading();
        }
    })
}


function getCard(_this) {
    apiGet("/app/user/money/card/get",{},function (res,code) {
        logJson(res,"/app/user/money/card/get")
        _this.card = res.data;
        setLocData("card",_this.card)
    })
}

function getMyCards(_this) {
    apiGet("/api/moneyUserCards",{},function (res,code) {
        logJson(res,"/api/moneyUserCards")
        _this.cards = res.data;
        // setLocData("card",_this.card)
    })
}
